﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Text;
using System.Data;
using RED_NET_Core.DAL;

namespace RED_NET_Core.BLL
{
   public class Album_PhotoBLL
    {
        private Album_Photo nAlbum_Photo;
        private NewsFeed_DAL nNewsFeedDal;

        public Album_PhotoBLL()
        {
            nAlbum_Photo = new Album_Photo();
            nNewsFeedDal = new NewsFeed_DAL();
        }

        #region [搜索特定用户的相册]

        public DataTable GetAllAlbumOfUserId(int nUserId)
        {
            try
            {
                return nAlbum_Photo.GetAllAlbumByUser(nUserId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region [新建相册]

        public void AddAlbumOfUserId(string nAlbumName,string nAlbumInfo,
            DateTime nAlbumUpdateTime,int nUserId,string nCoverPhotoUrl)
        {
            try
            {
                nAlbum_Photo.AddAlbum(nAlbumName, nAlbumInfo, nAlbumUpdateTime, nUserId, nCoverPhotoUrl);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region [更新相册]

        public void UpDateAlbum(int nAlbumId,string nAlbumName,string nAlbumInfo,
            DateTime nAlbumUpdateTime,string nCoverPhotoUrl)
        {
            try
            {
                nAlbum_Photo.UpdateAlbum(nAlbumId, nAlbumName, nAlbumInfo, nAlbumUpdateTime, nCoverPhotoUrl);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region [删除相册]

        public void DeleteAlbum(int nAlbumId)
        {
            try
            {
                nAlbum_Photo.DeleteAlbum(nAlbumId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region [搜索特定相册的照片]

        public DataTable SelectPhotoOfAlbum(int nAlbumId)
        {
            try
            {
                return nAlbum_Photo.GetAllPhotoByAlbum(nAlbumId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
       
        #region [获取对应相册的所有照片的URL]

        /// <summary>
        /// 获取相应相册里的所有照片的链接地址
        /// </summary>
        /// <param name="Album_Id"></param>
        /// <returns></returns>
        public ArrayList GetAllPhotoUrlByAlbum_JS(int Album_Id)
        {
            try
            {
                return (nAlbum_Photo.GetAllPhotoByAlbum_JS(Album_Id));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

       #endregion 

        #region [获取对应相册的所有照片缩略图的URL]

        /// <summary>
        /// 获取相应相册里的所有照片缩略图的链接地址
        /// </summary>
        /// <param name="Album_Id"></param>
        /// <returns></returns>
        public ArrayList GetAllSmallPhotoByAlbum_JS(int Album_Id)
        {
            try
            {
                return (nAlbum_Photo.GetAllSmallPhotoByAlbum_JS(Album_Id));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

       #endregion

        #region [添加相片]

        public void AddPhotoOfAlbum(int nAlbumId, string nPhotoName,
            string nPhotoInfo, DateTime nPhotoAddTime, string nPhotoUrl, string nSmallPhotoUrl, int User_Id)
        {
            try
            {
                int iPhotoId = nAlbum_Photo.AddPhoto(nAlbumId, nPhotoName, nPhotoInfo, nPhotoAddTime, nPhotoUrl, nSmallPhotoUrl,User_Id);
                if(iPhotoId > -1) nNewsFeedDal.InsertNewsFeed(User_Id, 0, nPhotoName, nPhotoUrl , nPhotoAddTime, iPhotoId, nAlbumId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region [更新相片]

        public void UpdatePhoto(int nPhotoId,string nPhotoName,string nPhotoComment,
            DateTime nUpdateTime,string nPhotoUrl)
        {
            try
            {
                int[] iIds = nAlbum_Photo.UpdatePhoto(nPhotoId, nPhotoName, nPhotoComment, nUpdateTime, nPhotoUrl);
                //iIds[0]为所更新照片的AlbumId，iIds[1]为用户ID
                nNewsFeedDal.InsertNewsFeed(iIds[1], 0, nPhotoName, nPhotoUrl, nUpdateTime, nPhotoId, iIds[0]);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region [删除相片]

        public void DeletePhoto(int nPhotoId)
        {
            try
            {
                nAlbum_Photo.DeletePhoto(nPhotoId);
                nNewsFeedDal.DeleteNewsFeed(0, nPhotoId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region[获取最新图片列表]
        /// <summary>
        /// 获取最新图片列表（自己的）
        /// </summary>
        /// <param name="nUId"></param>
        /// <param name="nNum">返回的图片张数</param>
        /// <returns></returns>
        public DataTable GetPhotoList(int nUId, int nNum)
        {
            try
            {
                return nAlbum_Photo.GetPhotoList(nUId, nNum);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    }
}